package com.dragon.english_practice_back.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.dragon.english_practice_back.entity.WordBook;
import com.dragon.english_practice_back.service.WordBookService;
import com.dragon.english_practice_back.mapper.WordBookMapper;
import lombok.AllArgsConstructor;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

/**
* @author 伫倚
* @description 针对表【word_book(单词书)】的数据库操作Service实现
* @createDate 2025-04-13 14:55:44
*/
@Service
@AllArgsConstructor
@Slf4j
public class WordBookServiceImpl extends ServiceImpl<WordBookMapper, WordBook>
    implements WordBookService{
    WordBookMapper wordBookMapper;

    @Override
    public List<WordBook> getLearningWordBook(int userId) {
        List<WordBook> learningWordBook = wordBookMapper.getLearningWordBook(userId);
        return learningWordBook;
    }

    @Override
    public List<WordBook> getLearnedWordBook(int userId) {
        List<WordBook> learnedWordBook = wordBookMapper.getLearnedWordBook(userId);
        return learnedWordBook;
    }

    @Override
    public Map<String, Boolean> getBookStatus(int userId, Integer wordBookId) {
        List<Map<String, Boolean>> status = wordBookMapper.checkWordBookStatus(userId, wordBookId );

        return status.get(0);
    }

    @Override
    @Transactional
    public boolean learnWordBook(int userId, Integer bookId) {
        wordBookMapper.learnWordBook(userId, bookId);
        wordBookMapper.cancelLearningStatus(userId, bookId);
        return true;
    }

    @Override
    public boolean unlearnWordBook(int userId, Integer bookId) {
        wordBookMapper.unlearnWordBook(userId, bookId);
        return true;
    }

    @Override
    public boolean deleteLearningRecord(int userId, Integer bookId) {
        wordBookMapper.deleteLearningRecord(userId, bookId);
        return true;
    }
}




